package com.flatfish.acvsystem.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate4.HibernateTemplate;

import com.flatfish.acvsystem.vo.PageVO;

/**
 * @author luohuida
 * @Time Mar 6, 2015
 * @Email luo.archer@gmail.com
 * @Description <b>增删改查组件规范接口</b>
 */
public interface IBaseHibernate {
	
	/**
	 * @param entity
	 * @return
	 * @throws Exception
	 * @Description <b>增加一个entity对象，返回是否添加成功 </b>
	 */
	public <T> boolean save(T entity) throws Exception;
	
	/**
	 * @param entity
	 * @return
	 * @throws Exception
	 * @Description <b></b>
	 */
	public <T> Integer saveAndGetId4Integer(T entity) throws Exception;
	
	 /**
	 * @param entity
	 * @return
	 * @throws Exception
	 * @Description <b>添加一个对象并且返回该对象的String类型的主键 </b>
	 */
	public <T> String saveAndGetId4String(T entity) throws Exception;  
	
	/**
	 * @param hql String hql语句 
	 * @return int 影响行数 
	 * @throws Exception
	 * @Description <b>传入hql语句执行</b>
	 */
	public int executeByHql(String hql) throws Exception; 

	/**
	 * @param hql 查询的hql语句 
	 * @return List集合 
	 * @throws Exception
	 * @Description <b>传入hql语句执行查询，返回list集合 </b>
	 */
	public <T> List<T> findByHql(String hql) throws Exception; 
	
	/**
	 * @param sql 查询的sql语句 
	 * @return List集合 
	 * @throws Exception
	 * @Description <b>传入sql语句执行查询，返回list集合 </b>
	 */
	public int executeBySql(String sql) throws Exception; 
	
	/**
	 * @param entity 
	 * @return boolean true/false 是否修改成功 
	 * @throws Exception
	 * @Description <b>修改entity对象，返回是否修改成功</b>
	 */
	public <T> boolean update(T entity) throws Exception;  
	
	 /**
	 * @param hql
	 * @return
	 * @throws Exception
	 * @Description <b>传入hql语句执行修改，返回是否修改成功</b>
	 */
	public boolean update(String hql) throws Exception;  
	
	/**
	 * @param hql
	 * @return int 返回修改的行数 
	 * @throws Exception
	 * @Description <b>执行修改的hql语句，返回修改的行数</b>
	 */
	public int updateByHql(String hql) throws Exception; 
	
	/**
	 * @param entity
	 * @return
	 * @throws Exception
	 * @Description <b>传入一个将要删除的entity对象，返回删除是否成功</b>
	 */
	public <T> boolean delete(T entity) throws Exception; 
	
	/**
	 * @param c
	 * @param id
	 * @return
	 * @throws Exception
	 * @Description <b>传入一个entity对象Class和String型主键，返回该对象</b>
	 */
	public <T> T getById(Class<T> c, String id) throws Exception;
	
	/**
	 * @param c
	 * @param id
	 * @return
	 * @throws Exception
	 * @Description <b>传入一个entity对象Class和Serializable类型主键，返回该对象</b>
	 */
	public <T> T get(Class<T> c, Serializable id) throws Exception;  
	
	/**
	 * @param hql
	 * @return
	 * @throws Exception
	 * @Description <b>传入hql语句，查询对象 </b>
	 */
	public <T> T get(String hql) throws Exception;
	
	/**
	 * @param hql
	 * @return
	 * @throws Exception
	 * @Description <b>通过hql语句查询List集合 </b>
	 */
	public <T> List<T> getList(String hql) throws Exception; 
	
	/**
	 * @param hql
	 * @return
	 * @throws Exception
	 * @Description <b>传入删除的hql语句，删除记录</b>
	 */
	public boolean delete(String hql) throws Exception;  
	
	/**
	 * @param c
	 * @return
	 * @throws Exception
	 * @Description <b>动态查询 </b>
	 */
	public <T> List<T> getList(Class<T> c) throws Exception;  
	
	/**
	 * @param hql 查询的hql语句 
	 * @param obj 查询参数 
	 * @return
	 * @throws Exception
	 * @Description <b>传入hql查询语句和object数组类型的参数，返回查询list集合 </b>
	 */
	public <T> List<T> getList(String hql, Object[] obj) throws Exception;  
	
	/**
	 * @param queryHql 查询记录hql语句
	 * @param queryCountHql 查询记录条数hql语句 
	 * @param firstResult 当前查询页 
	 * @param maxResult 每页显示多少条
	 * @return List返回集合 集合0保存查询结果、集合1保存总记录条数 
	 * @throws Exception
	 * @Description <b>传入查询语句和查询总条数（总记录）的hql语句、当前页数、每页显示调试数；返回查询后的list集合,
	 * list集合保存总记录调试和记录结果</b>
	 */
	public List<?> showPage(String queryHql, String queryCountHql, int firstResult, int maxResult) throws Exception;
	
	/**
	 * @param queryHql
	 * @param queryCountHql
	 * @param page
	 * @throws Exception
	 * @Description <b>传入查询语句和查询总条数（总记录）的hql语句、page分页对象；返回查询后的list集合</b>
	 */
	public <T> void showPage(String queryHql, String queryCountHql, PageVO<T> page) throws Exception;
	
	/**
	 * @param queryCountHql
	 * @param cResult
	 * @param firstResult
	 * @param maxResult
	 * @return
	 * @throws Exception
	 * @Description <b>分页查询，传入查询count的hql语句和DetachedCriteria动态查询条件进行查询分页 </b>
	 */
	public List<?> showPage(String queryCountHql, DetachedCriteria cResult, int firstResult, int maxResult) throws Exception;  
	
	/**
	 * @param queryCountHql
	 * @param cResult
	 * @param page
	 * @throws Exception
	 * @Description <b>分页查询，传入查询的count的hql语句和动态查询DetachedCriteria类及page分页entity </b>
	 */
	public <T> void showPage(String queryCountHql, DetachedCriteria cResult, PageVO<T> page) throws Exception; 
	
	/**
	 * @param dc
	 * @return
	 * @throws Exception
	 * @Description <b>传入查询条件DetachedCriteria进行查询</b>
	 */
	public <T> List<T> find(DetachedCriteria dc) throws Exception;
	
	/**
	 * @return
	 * @Description <b>暴露基类session供用户使用 </b>
	 */
	public Session getSession();
	
	/**
	 * @return
	 * @Description <b>暴露HibernateTemplate模板，当基类（增删改查组件）方法不够用可以用模板进行操作</b>
	 */
	public HibernateTemplate getTemplate();  
}
